//
//  WHScanController.m
//  BinFengExpressOwner
//
//  Created by 邓伟浩 on 2018/10/17.
//  Copyright © 2018年 BinFeng. All rights reserved.
//

#import "WHScanController.h"
#import <AVFoundation/AVFoundation.h>

@interface WHScanController ()<AVCaptureMetadataOutputObjectsDelegate>

@property (nonatomic, strong) AVCaptureSession *session;
@property (nonatomic, strong) UIImageView *lineImageView;
@property (nonatomic, strong) UIImageView *centerImageView;

@end

@implementation WHScanController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.naviType = NaviTypeClear;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self setLeftBarItem:self.isVideoAvalible];
}

- (void)setLeftBarItem:(BOOL)isWhite {
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(0, 0, 40, kNavBarHeight);
    [backButton addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
    if (isWhite) {
        [backButton setImage:IMAGE_NAMED(@"icon_menu_whiteBack") forState:UIControlStateNormal];
    } else {
        [backButton setImage:IMAGE_NAMED(@"icon_menu_back") forState:UIControlStateNormal];
    }
    
    UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = back;
}

- (void)back:(UIButton *)back {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)outPutReadableObject:(AVMetadataMachineReadableCodeObject *)metadataObject {
    //输出扫描字符串
    NSString *dataStr = metadataObject.stringValue;
    DLog(@"dataStr = %@", dataStr);
    
    kWeakSelf(self);
    [self dismissViewControllerAnimated:YES completion:^{
        if (weakself.outPutStr) {
            weakself.outPutStr(dataStr);
        }
    }];
}




@end
